﻿#region Copyright (c) 2000-2013 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{                                                                   }
{                                                                   }
{       Copyright (c) 2000-2013 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2013 Developer Express Inc.

using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using UColor.Core.Helpers;
using UColor.Core.Utils;
#if !SL
using System.Drawing.Printing;
using DevExpress.Internal.DXWindow;
#endif
using System.Windows.Interop;
using System.Runtime.InteropServices;
using UColor.Core;
namespace UColor.Core.Parts {
   
#if !SL
	public class UCWindow : DXWindow, IBackButton {
		internal static UCWindow MainUCWindow { get; private set; }
        public UCWindow()
        {
            MainUCWindow = this;
            Stream rdStream = AssemblyHelper.GetEmbeddedResourceStream(typeof(UCWindow).Assembly, GetXamlPath(), false);
			ResourceDictionary rd = (ResourceDictionary)XamlReader.Load(rdStream);
			if(rd == null) return;
            ((Image)rd["MinimizeButtonImage"]).Source = ImageSourceHelper.GetImageSource(AssemblyHelper.GetResourceUri(typeof(UCWindow).Assembly, "Images/Window/Minimize.png"));
            ((Image)rd["RestoreButtonImage"]).Source = ImageSourceHelper.GetImageSource(AssemblyHelper.GetResourceUri(typeof(UCWindow).Assembly, "Images/Window/Restore.png"));
            ((Image)rd["MaximizeButtonImage"]).Source = ImageSourceHelper.GetImageSource(AssemblyHelper.GetResourceUri(typeof(UCWindow).Assembly, "Images/Window/Maximize.png"));
            ((Image)rd["CloseButtonImage"]).Source = ImageSourceHelper.GetImageSource(AssemblyHelper.GetResourceUri(typeof(UCWindow).Assembly, "Images/Window/Close.png"));
            Style = (Style)rd["Window"];
			SetUseLayoutRounding();
		}
		protected virtual string GetXamlPath() {
			return "Window/Window.xaml";
		}
		void SetUseLayoutRounding() {
            System.Reflection.PropertyInfo useLayoutRoundingInfo = typeof(UCWindow).GetProperty("UseLayoutRounding", typeof(bool));
			if(useLayoutRoundingInfo != null) {
				useLayoutRoundingInfo.SetValue(this, true, null);
			}
		}
		bool IBackButton.DesiredVisibility { get { return false; } }
		event EventHandler IBackButton.DesiredVisibilityChanged {
			add { }
			remove { }
		}
		bool IBackButton.ActualVisibility {
			get {
				return false;
			}
			set {
			}
		}
		void IBackButton.DoClick() { }
		event EventHandler IBackButton.Click {
			add { }
			remove { }
		}
        internal void SetMainBackButton(ButtonExt backButton)
        {
            IntercallHelper.RegisterMainBackButton(this);
        }
	}
    public class CenterWindow : UCWindow
    {
		protected override string GetXamlPath() {
			return "Window/CenterWindow.xaml";
		}
	}
#endif
	public abstract class UCStartupBase : StartupBase {
		protected override bool DoStartup() {
			if(!base.DoStartup()) return false;
			MinWidth = 800.0;
			MinHeight = 550.0;
			MainElementMinHeight = 450.0;
			MainElementMinWidth = 560.0;
			Size size = new Size(1280.0, 830.0);
#if !SL
			size = GetSize(new Size(MinWidth, MinHeight), size, out this.maximizeWindow);
#endif
			Width = size.Width;
			Height = size.Height;
			return true;
		}
#if !SL
		bool maximizeWindow;
		protected override Window CreateMainWindow() {
            UCWindow w = new UCWindow();
			w.Loaded += OnWindowLoaded;
			return w;
		}
		void OnWindowLoaded(object sender, RoutedEventArgs e) {
			Window w = (Window)sender;
			if(this.maximizeWindow)
				w.WindowState = WindowState.Maximized;
		}
#endif
	}
}
